package com.billdowney.service.interfaces.base;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * Specification拼接参数
 * 
 * @author 超级小富翁 - BillDowney
 * @date 2019年4月25日 下午4:23:07
 */
public class SpecParam {

	/**
	 * 等于
	 */
	private Map<String, Object> equal;
	/**
	 * 不等于
	 */
	private Map<String, Object> notEqual;
	/**
	 * 小于
	 */
	private Map<String, Comparable<Object>> lessThan;
	/**
	 * 小于等于
	 */
	private Map<String, Comparable<Object>> lessThanOrEqualTo;
	/**
	 * 大于
	 */
	private Map<String, Comparable<Object>> greaterThan;
	/**
	 * 大于等于
	 */
	private Map<String, Comparable<Object>> greaterThanOrEqualTo;
	/**
	 * 等于模糊匹配
	 */
	private Map<String, String> like;
	/**
	 * 不等于模糊匹配
	 */
	private Map<String, String> notLike;
	/**
	 * 等于null
	 */
	private Set<String> isNull;
	/**
	 * 不等于null
	 */
	private Set<String> isNotNull;
	/**
	 * 等于空，包含null，空字符串
	 */
	private Set<String> isEmpty;
	/**
	 * 不等于空，包含null，空字符串
	 */
	private Set<String> isNotEmpty;
	/**
	 * 正序
	 */
	private Set<String> asc;
	/**
	 * 倒序
	 */
	private Set<String> desc;
	/**
	 * 包含多个数据
	 */
	private Map<String, Set<Object>> in;
	/**
	 * 不包含多个数据
	 */
	private Map<String, Set<Object>> notIn;
	/**
	 * 存储已经保存的类型
	 */
	private Set<SpecType> specTypes;

	public SpecParam() {
		super();
		this.equal = new HashMap<>();
		this.notEqual = new HashMap<>();
		this.lessThan = new HashMap<>();
		this.lessThanOrEqualTo = new HashMap<>();
		this.greaterThan = new HashMap<>();
		this.greaterThanOrEqualTo = new HashMap<>();
		this.like = new HashMap<>();
		this.notLike = new HashMap<>();
		this.isNull = new HashSet<>();
		this.isNotNull = new HashSet<>();
		this.isEmpty = new HashSet<>();
		this.isNotEmpty = new HashSet<>();
		this.asc = new HashSet<>();
		this.desc = new HashSet<>();
		this.in = new HashMap<>();
		this.notIn = new HashMap<>();
		this.specTypes = new HashSet<>();
	}

	public Map<String, Object> getEqual() {
		return equal;
	}

	public Map<String, Object> getNotEqual() {
		return notEqual;
	}

	public Map<String, Comparable<Object>> getLessThan() {
		return lessThan;
	}

	public Map<String, Comparable<Object>> getLessThanOrEqualTo() {
		return lessThanOrEqualTo;
	}

	public Map<String, Comparable<Object>> getGreaterThan() {
		return greaterThan;
	}

	public Map<String, Comparable<Object>> getGreaterThanOrEqualTo() {
		return greaterThanOrEqualTo;
	}

	public Map<String, String> getLike() {
		return like;
	}

	public Map<String, String> getNotLike() {
		return notLike;
	}

	public Set<String> getIsNull() {
		return isNull;
	}

	public Set<String> getIsNotNull() {
		return isNotNull;
	}

	public Set<String> getIsEmpty() {
		return isEmpty;
	}

	public Set<String> getIsNotEmpty() {
		return isNotEmpty;
	}

	public Set<String> getAsc() {
		return asc;
	}

	public Set<String> getDesc() {
		return desc;
	}

	public Map<String, Set<Object>> getIn() {
		return in;
	}

	public Map<String, Set<Object>> getNotIn() {
		return notIn;
	}

	public Set<SpecType> getSpecTypes() {
		return specTypes;
	}

	public void setEqual(Map<String, Object> equal) {
		this.equal = equal;
		this.specTypes.add(SpecType.equal);
	}

	public void setNotEqual(Map<String, Object> notEqual) {
		this.notEqual = notEqual;
		this.specTypes.add(SpecType.notEqual);
	}

	public void setLessThan(Map<String, Comparable<Object>> lessThan) {
		this.lessThan = lessThan;
		this.specTypes.add(SpecType.lessThan);
	}

	public void setLessThanOrEqualTo(Map<String, Comparable<Object>> lessThanOrEqualTo) {
		this.lessThanOrEqualTo = lessThanOrEqualTo;
		this.specTypes.add(SpecType.lessThanOrEqualTo);
	}

	public void setGreaterThan(Map<String, Comparable<Object>> greaterThan) {
		this.greaterThan = greaterThan;
		this.specTypes.add(SpecType.greaterThan);
	}

	public void setGreaterThanOrEqualTo(Map<String, Comparable<Object>> greaterThanOrEqualTo) {
		this.greaterThanOrEqualTo = greaterThanOrEqualTo;
		this.specTypes.add(SpecType.greaterThanOrEqualTo);
	}

	public void setLike(Map<String, String> like) {
		this.like = like;
		this.specTypes.add(SpecType.like);
	}

	public void setNotLike(Map<String, String> notLike) {
		this.notLike = notLike;
		this.specTypes.add(SpecType.notLike);
	}

	public void setIsNull(Set<String> isNull) {
		this.isNull = isNull;
		this.specTypes.add(SpecType.isNull);
	}

	public void setIsNotNull(Set<String> isNotNull) {
		this.isNotNull = isNotNull;
		this.specTypes.add(SpecType.isNotNull);
	}

	public void setIsEmpty(Set<String> isEmpty) {
		this.isEmpty = isEmpty;
		this.specTypes.add(SpecType.isEmpty);
	}

	public void setIsNotEmpty(Set<String> isNotEmpty) {
		this.isNotEmpty = isNotEmpty;
		this.specTypes.add(SpecType.isNotEmpty);
	}

	public void setAsc(Set<String> asc) {
		this.asc = asc;
		this.specTypes.add(SpecType.asc);
	}

	public void setDesc(Set<String> desc) {
		this.desc = desc;
		this.specTypes.add(SpecType.desc);
	}

	public void setIn(Map<String, Set<Object>> in) {
		this.in = in;
		this.specTypes.add(SpecType.in);
	}

	public void setNotIn(Map<String, Set<Object>> notIn) {
		this.notIn = notIn;
		this.specTypes.add(SpecType.notIn);
	}

	public void addEqual(String field, Object value) {
		this.equal.put(field, value);
		this.specTypes.add(SpecType.equal);
	}

	public void addNotEqual(String field, Object value) {
		this.notEqual.put(field, value);
		this.specTypes.add(SpecType.notEqual);
	}

	public void addLessThan(String field, Comparable<Object> value) {
		this.lessThan.put(field, value);
		this.specTypes.add(SpecType.lessThan);
	}

	public void addLessThanOrEqualTo(String field, Comparable<Object> value) {
		this.lessThanOrEqualTo.put(field, value);
		this.specTypes.add(SpecType.lessThanOrEqualTo);
	}

	public void addGreaterThan(String field, Comparable<Object> value) {
		this.greaterThan.put(field, value);
		this.specTypes.add(SpecType.greaterThan);
	}

	public void addGreaterThanOrEqualTo(String field, Comparable<Object> value) {
		this.greaterThanOrEqualTo.put(field, value);
		this.specTypes.add(SpecType.greaterThanOrEqualTo);
	}

	public void addLike(String field, String value) {
		this.like.put(field, value);
		this.specTypes.add(SpecType.like);
	}

	public void addNotLike(String field, String value) {
		this.notLike.put(field, value);
		this.specTypes.add(SpecType.notLike);
	}

	public void addIsNull(String... field) {
		for (String str : field) {
			this.isNull.add(str);
		}
		this.specTypes.add(SpecType.isNull);
	}

	public void addIsNotNull(String... field) {
		for (String str : field) {
			this.isNotNull.add(str);
		}
		this.specTypes.add(SpecType.isNotNull);
	}

	public void addIsEmpty(String... field) {
		for (String str : field) {
			this.isEmpty.add(str);
		}
		this.specTypes.add(SpecType.isEmpty);
	}

	public void addIsNotEmpty(String... field) {
		for (String str : field) {
			this.isNotEmpty.add(str);
		}
		this.specTypes.add(SpecType.isNotEmpty);
	}

	public void addAsc(String... field) {
		for (String str : field) {
			this.asc.add(str);
		}
		this.specTypes.add(SpecType.asc);
	}

	public void addDesc(String... field) {
		for (String str : field) {
			this.desc.add(str);
		}
		this.specTypes.add(SpecType.desc);
	}

	public void addIn(String field, Object... value) {
		if (this.in.containsKey(field)) {
			for (Object obj : value) {
				this.in.get(field).add(obj);
			}
		} else {
			Set<Object> set = new HashSet<>();
			for (Object obj : value) {
				set.add(obj);
			}
			this.in.put(field, set);
		}
		this.specTypes.add(SpecType.in);
	}

	public void addNotIn(String field, Object... value) {
		if (this.notIn.containsKey(field)) {
			for (Object obj : value) {
				this.notIn.get(field).add(obj);
			}
		} else {
			Set<Object> set = new HashSet<>();
			for (Object obj : value) {
				set.add(obj);
			}
			this.notIn.put(field, set);
		}
		this.specTypes.add(SpecType.notIn);
	}

}
